import apis from "@/http/apis.js";
export default ({
    namespaced: true,
    state: {
        types: [],
        typeById: []
    },
    getters: {

    },

    mutations: {
        typesData(state, data) {
            state.types = data;
        },
    },

    actions: {
        async getAllTypes(context) {
            const {
                data
            } = await apis.types.getAllTypes()
            console.log(data);
            context.commit("typesData", data.data)
        },

        async delTypesById(context, _id) {
            const {
                data
            } = await apis.types.delTypesById({
                _id
            })
            if (data.status) {
                return data
            }
        },

        async addTypes(context, type) {
            const { data } = await apis.types.addTypes({
                ...type,
            });
            return data
        },

        async getTypesById(context, _id) {
            const { data } = await apis.types.getTypesById({
                _id
            });
            if (data.status) {
                context.state.typeById = data.data[0];
            }
        },

        async changeTypesById(context, type) {
            const { data } = await apis.types.changeTypesById({
                ...type,
            });
            return data
        },

    },
    modules: {

    }
})